package com.ww.juc.futureandcallable;

import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class SubmitRunnableAndResultTest {
	
	public static void main(String[] args) {
		try {
			UserInfo userInfo = new UserInfo();
			SubmitRunnableAndResult runnableAndResult = new SubmitRunnableAndResult(userInfo);
			ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(10, 10, 10, TimeUnit.SECONDS, new LinkedBlockingDeque<Runnable>());
			Future<UserInfo> future = poolExecutor.submit(runnableAndResult, userInfo);
			System.out.println("开始时间：" + System.currentTimeMillis());
			System.out.println("调用get方法之前：" + userInfo.getUsername());
			userInfo = future.get();
			System.out.println("get获取值：" + userInfo.getUsername());
			System.out.println("结束时间：" + System.currentTimeMillis());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
